{if $smarty.get.type neq "edit"}
    <div id="dialog-add-item-select-section" style="display:none;"></div>
    <form action="" method="post" id="form-add-item-select-section">
       <input type="hidden" name="type" value="add" />
       <input type="hidden" name="parent" value="{$smarty.get.catalog_parent}" />
       <input type="hidden" name="por" value="{$Field.por}">
    </form>
	<script type="text/javascript">
    $(function(){
		var _d_select = $("#dialog-add-item-select-section");
		var _d_form   = $("#form-add-item-select-section");
		var _d_text   = '<p>Пожалуйста выберите тип раздела!</p>{$section_type}';
		_d_select.html(_d_text);		
		_d_select.dialog({
			modal     : true,
			resizable : false,
			width     : 350,
			zIndex    : 10000,
			title     : "Внимание!",
			buttons : {
				"Создать":function() {
					var _s_value = $("select option:selected", _d_select).attr("value");
					$("<input />").attr({
						"type"  : "hidden",
						"name"  : "section_type",
						"value"	: _s_value						
					}).appendTo(_d_form);
					_d_form.attr("action", '/admin/?m=content&id={$smarty.get.id}&parent={$smarty.get.parent}&catalog_parent={$smarty.get.catalog_parent}&catalog_id={$ID_ACTION}&type=edit').submit();
					_d_form.submit();				
				},
				"Отмена":function(){
					document.location.href = '/admin/?m=content&id={$smarty.get.id}&parent={$smarty.get.parent}&catalog_parent={$smarty.get.catalog_parent}';
					_d_select.dialog("close");				
				}
			}
		});
		/* Скрываем кнопку закрыть */
		$(".ui-dialog-titlebar-close").hide();
	});    
    </script>
{else}

<form action="" method="post" enctype="multipart/form-data" id="form_submit" class="form_submit">
  {if $smarty.get.type eq "edit"}
  	<input type="hidden" name="type" value="editt" />
    <input type="hidden" name="id" value="{$smarty.get.catalog_id}" />
  {else}
  	<input type=hidden name="type" value="add" />
  {/if}
  
  <input type="hidden" name="parent" value="{$smarty.get.catalog_parent}" />
  <div id="admin_tabs_main_content"> 
    <!-- TABS_NAME -->
    <ul>
      <li><a href="#General">Общие</a></li>
      {if $Field.section_type neq "complete"}
      <li><a href="#SEO">SEO</a></li>      
      {elseif $Field.section_type eq "complete"}
      <li><a href="#standart">Стандартные опции</a></li>
      <li><a href="#additionally">Дополнительные опции</a></li>
      {/if} 
     <li><a href="#Files">Файлы</a></li>
    </ul>
    <!-- END TABS_NAME --> 
    <!-- ОБЩИЕ -->
    <div id="dialog-form-alert"></div>
    <div id="General" style="width:730px;">      
      <p class="position_name">Порядок</p>
      <p class="position_input"><input type="text" name="por" value="{$Field.por}" class="por-field"></p>
      <p class="position_name">Активна</p>
      <p class="position_input"><input type="checkbox" class="mini-switch" name="show" value="1"{if $Field.show} checked="checked"{/if} /></p>
      
      <!--<p class="position_name">Родительская группа</p>
      <p class="position_input">{$GROUPS}</p>  -->
              
      <p class="position_name">Название страницы</p>
      <p class="position_input"><input type="text" name="name" value="{$Field.name}" class="name"></p>
      
      <p class="position_name">Системное имя</p>
      <p class="position_input"><input type="text" name="sys_name" value="{$Field.sys_name}" class="sys_name"></p>
      
      <p class="position_name">Редирект</p>
      <p class="position_input"><input type="text" name="redirect" value="{$Field.redirect}"></p>
      
      <p class="position_name">Тип раздела</p>
      <p class="position_input">{$section_type}</p>
	  
      {if $Field.section_type eq "default" || !$Field.section_type}
      
      <p class="position_name">Цена</p>
      <p class="position_input"><input type="text" name="worth" value="{$Field.worth}"></p>
      
      <p class="position_name">Описание</p>
	  <p class="position_input"><textarea name="btext" rows="5" class="elrte_wo">{$Field.btext}</textarea></p>
      
      <p class="position_name">Текст в шапке</p>
      <p class="position_input"><textarea name="text_top" rows="5" class="elrte_wo">{$Field.text_top}</textarea></p>
      
      <p class="position_name">Панель справа</p>
      <p class="position_input"><textarea name="text_right" rows="5" class="elrte_wo">{$Field.text_right}</textarea></p>
      
      <!--<p class="position_name">Категория</p>
      <p class="position_input">{$BODY_SELECT}</p>  

      <p class="position_name">Кол-во дверей</p>
      <p class="position_input">{$DOORS_SELECT}</p>-->    
      
      {elseif $Field.section_type eq "gallery"}
      <p class="position_name">Описание</p>
	  <p class="position_input"><textarea name="btext" rows="10">{$Field.btext}</textarea></p>
      <!--<p class="position_name">Заголовок в галереи</p>
	  <p class="position_input"><textarea name="text_banner" rows="3">{$Field.text_banner}</textarea></p>-->
      
      {elseif $Field.section_type eq "review"}
      <p class="position_name">Описание</p>
	  <p class="position_input"><textarea name="btext" rows="5" class="elrte_wo">{$Field.btext}</textarea></p>
      
      <!--<p class="position_name">Цвет текста в главном баннере</p>
	  <p class="position_input"><input type="radio" name="color_text" value="black"{if $Field.color_text eq "black" || !$Field.color_text} checked="checked"{/if}> Стандартный(черный) <input type="radio" name="color_text" value="white"{if $Field.color_text eq "white"} checked="checked"{/if}> Белый</p>
      <p class="position_name">Заголовок в баннере</p>
	  <p class="position_input"><textarea name="text_banner" rows="3">{$Field.text_banner}</textarea></p>      
      <p class="position_name">Короткий текст в баннере</p>
	  <p class="position_input"><textarea name="stext" rows="3">{$Field.stext}</textarea></p>-->
      
      {elseif $Field.section_type eq "highlights"}
      <p class="position_name">Короткий текст в хайлайте</p>
	  <p class="position_input"><textarea name="stext" rows="3">{$Field.stext}</textarea></p>
      <p class="position_name">Описание</p>
	  <p class="position_input"><textarea name="btext" rows="5" class="elrte_wo">{$Field.btext}</textarea></p>
      <p class="position_name">Pos X</p>
      <p class="position_input"><input type="text" name="pos_x" value="{$Field.pos_x}" class="por-field"></p>
      <p class="position_name">Pos Y</p>
      <p class="position_input"><input type="text" name="pos_y" value="{$Field.pos_y}" class="por-field"></p>      
      
      {elseif $Field.section_type eq "complete"}
        <p class="position_name">Тип двигателя</p>
        <p class="position_input">{$ENGINE_RADIO}</p>
      
        <p class="position_name">Цена, от</p>
        <p class="position_input"><input type="text" name="price_from" value="{$Field.price_from}" style="width:50%"></p>
      
        <p class="position_name">Цена, до</p>
        <p class="position_input"><input type="text" name="price_to" value="{$Field.price_to}" style="width:50%"></p>
        
        <p class="position_name">Обзор</p>
        <p class="position_input"><textarea name="btext" rows="5" class="elrte_wo">{$Field.btext}</textarea></p>
        
        
      {elseif $Field.section_type eq "press"}
        <p class="position_name">Источник</p>
        <p class="position_input"><input type="text" name="source" value="{$Field.source}"></p>
        
        <p class="position_name">Дата</p>
        <p class="position_input"><input type="text" name="date" value="{$Field.date}" class="datepicker" style="width:100px;"></p>    
           
        <p class="position_name">Описание</p>
        <p class="position_input"><textarea name="stext" rows="5">{$Field.stext}</textarea></p>
      
      {/if}     
    </div>
    
    {if $Field.section_type neq "complete"}    
    <div id="SEO" style="width:730px;">
      <p class="position_name">Title</p>
      <p class="position_input"><textarea name="title" id="textform1" rows="3">{$Field.title}</textarea><div id="charlimitinfo1"></div></p>
      
      <p class="position_name">Description</p>
      <p class="position_input"><textarea name="description" id="textform2" rows="3">{$Field.description}</textarea><div id="charlimitinfo2"></div></p>
      
      <p class="position_name">Keywords</p>
      <p class="position_input"><textarea name="keywords" id="textform3" rows="3">{$Field.keywords}</textarea><div id="charlimitinfo3"></div></p>
    </div>    
    {elseif $Field.section_type eq "complete"}
	 <style type="text/css">
        #options {
            margin:1em 0;
            border-collapse:collapse;
            width:100%;
        }
        #options td, 
        #options th {
            border:1px solid #eee;
            padding:.6em 10px;
            text-align:left;
        }
      </style>    
      <!-- Диалог добавления опции -->
      <div id="dialog-form" style="display:none;" title="Добавить опцию">
        <p class="validateTips">Пожалуйста, заполните все поля!</p>
        <input type="hidden" name="type_option" value="" />  
        <table width="100%">
          <tr>
            <td style="width:200px"><strong>Название:</strong></td>
            <td><input type="text" name="name_option" value="" class="text ui-widget-content ui-corner-all" /></td>
          </tr>
          <tr>
            <td style="width:200px"><strong>Описание:</strong></td>
            <td><textarea name="text_option" class="text ui-widget-content ui-corner-all" rows="5"></textarea></td>
          </tr>            
        </table>        
      </div>
      <!-- END Диалог добавление пользователя -->    
    
      <div id="standart">       
        <table id="options" class="ui-widget ui-widget-content">
          <thead>
            <tr class="ui-widget-header">
              <th>Название</th>
              <th>Описание</th>              
              <th width="18">&times;</th>
            </tr>
          </thead>
          <tbody>
          {if $option_list.standart}
              {foreach $option_list.standart as $Key => $Value}
                <tr id_item="{$Value.id}" type_option="standart">
                  <td>{$Value.name}</td>
                  <td>{$Value.text}</td>
                  <td><a class="deleteItem" href="javascript:void(0);"><img src="/templates/admin/img/cancel.png" alt="удалить" /></a></td>
                </tr>
              {/foreach}
          {else}
          <tr class="none_items">
            <td colspan="3" style="text-align:center;">Нет записей!</td>
          </tr>
          {/if}
          </tbody>
        </table>
        <p><a href="javascript:void(0);" id="create-option-standart" rel="standart" class="ui_wo_buttons ui-state-default ui-corner-all"><span class="ui-icon ui-icon-plus"></span> Добавить опцию</a></p>
      </div>
      
      <div id="additionally">
        <table id="options" class="ui-widget ui-widget-content">
          <thead>
            <tr class="ui-widget-header">
              <th>Название</th>
              <th>Описание</th>              
              <th width="18">&times;</th>
            </tr>
          </thead>
          <tbody>
          {if $option_list.additionally}
              {foreach $option_list.additionally as $Key => $Value}
                <tr id_item="{$Value.id}" type_option="additionally">
                  <td>{$Value.name}</td>
                  <td>{$Value.text}</td>
                  <td><a class="deleteItem" href="javascript:void(0);"><img src="/templates/admin/img/cancel.png" alt="удалить" /></a></td>
                </tr>
              {/foreach}
          {else}
          <tr class="none_items">
            <td colspan="3" style="text-align:center;">Нет записей!</td>
          </tr>
          {/if}
          </tbody>
        </table>
        <p><a href="javascript:void(0);" id="create-option-additionally" rel="additionally" class="ui_wo_buttons ui-state-default ui-corner-all"><span class="ui-icon ui-icon-plus"></span> Добавить опцию</a></p>
      </div>      
      
      <script type="text/javascript">
		$(function() 
		{        
			/* Удаление опции */
			$("a.deleteItem").live("click", function()
			{
				if(confirm("Вы уверены, что хотите удалить опцию?")) {
					var _this_tr = $(this).parent().parent();
					var _id_item = _this_tr.attr("id_item");
					var _type_option = _this_tr.attr("type_option");					
					$.post(location.href, {
						"type_action" : "delete_option",				
						"id_item"     : _id_item
					}, function(data) {
						if(data != null) {
							if(data.success) {
								alert(data.success);
								_this_tr.remove();
								if($("#"+_type_option+" tbody tr").size() == "0") {
									$("#"+_type_option+" tbody").html('<tr class="none_items"><td colspan="3" style="text-align:center;">Нет записей!</td></tr>');	
								}
							}
							else if(data.error) {
								alert(data.error);
							}					
						}
					});					
				}
			});	
			
			var _dialog_option = $("#dialog-form");				
			_dialog_option.dialog({
				autoOpen: false,
				height : 300,
				width  : 600,
				zIndex : 10000,
				modal: true,
				resizable:false,
				buttons:
				{
					"Добавить": function()
					{						
						var _el_name_option   = $("input[type=text]", _dialog_option);
						var _el_type_option   = $("input[type=hidden]", _dialog_option);
						var _el_text_option   = $("textarea", _dialog_option);
						var _type_option_value = _el_type_option.attr("value");		
						var _el_parent_option = {$ID_ACTION};
						if(_el_name_option.attr("value") == '') {
							alert("Не заполнено поле \"Название\"!");
							_el_name_option.focus();
						}
						else if(_el_text_option.attr("value") == '') {
							alert("Не заполнено поле \"Описание\"!");
							_el_text_option.focus();
						} 
						else
						{							
							$.post(location.href, {
								"type_action"   : "add_option",
								"name_option"   : _el_name_option.attr("value"),							
								"text_option"   : _el_text_option.attr("value"),
								"type_option"   : _type_option_value,								
								"parent_option" : _el_parent_option
							}, function(data){
								if(data != null) {															
									$("#"+_type_option_value+" tbody .none_items").remove();									
									$("#"+_type_option_value+" table tbody").append('<tr id_item="' + data.metadata.id + '" type_option="' + _type_option_value + '">' +
									"<td>" + data.metadata.name + "</td>" +
									"<td>" + data.metadata.text + "</td>" +
									'<td><a class="deleteItem" href="javascript:void(0);"><img src="/templates/admin/img/cancel.png" alt="удалить" /></a></td></tr>');
									_el_name_option.attr("value", '');
									_el_text_option.attr("value", '');
									_el_type_option.attr("value", '');
								}
							}, "json");					
							$(this).dialog("close");
						}
					},
					"Отмена": function() {
						$(this).dialog("close");
					}
				}
			});
			$("#create-option-standart, #create-option-additionally").click(function() {
				$("input[type=hidden]", _dialog_option).attr("value", $(this).attr("rel"));
				setTimeout(function(){				
					_dialog_option.dialog("open");
				}, 600);
			});
		});
		</script>  
    {/if}
    
    <div id="Files">
      {$IMAGE}     
    </div>  
    
  </div>
  <div id="posbutton">
    <a href="javascript:void(0);" class="ui_wo_buttons but_primenit ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span>Применить</a> 
    <a href="javascript:void(0);" class="ui_wo_buttons but_save ui-state-default ui-corner-all"><span class="ui-icon ui-icon-disk"></span>Сохранить</a>
  </div>  
</form>
<script type="text/javascript">
$(function()
{
	$(".name").GoogleTranslate("{$TABLE}", {$ID_ACTION});
	var eForm = $("#form_submit");
	$(".but_primenit").live("click", function(){
		eForm.attr("action", '?m=content&id={$smarty.get.id}&parent={$smarty.get.parent}&catalog_id={$ID_ACTION}&catalog_parent={$smarty.get.catalog_parent}&type=edit').submit();		
	});		
	$(".but_save").live("click", function(){
		eForm.attr("action", '?m=content&id={$smarty.get.id}&parent={$smarty.get.parent}&catalog_parent={$smarty.get.catalog_parent}').submit();
	});
});
</script>
{/if}